package main

import (
	"context"
	"fmt"
	greeter "go_final/demos/grpc_metadata/protofile"
	"net"

	"google.golang.org/grpc"
	"google.golang.org/grpc/metadata"
)

type Greeter struct{}

func (g Greeter) SayHi(ctx context.Context, request *greeter.SayHiRequest) (*greeter.SayHiResponse, error) {
	md, ok := metadata.FromIncomingContext(ctx)
	if ok {
		fmt.Println("md", md)
	}
	return &greeter.SayHiResponse{
		Reply: "I'm fine!",
	}, nil
}

func main() {
	s := grpc.NewServer()
	greeter.RegisterGreeterServer(s, &Greeter{})
	lis, err := net.Listen("tcp", ":8080")
	if err != nil {
		panic(err)
	}
	s.Serve(lis)
}
